package models

import (
	"github.com/astaxie/beego/orm"
	"time"
)

type Order struct {
	Id             int       `orm:"pk;auto"` //自增型主键ID
	ActivityId     int       `orm:"size(32);null"`
	TicketPwd      string    `orm:"size(64);null"`
	TicketNo       string    `orm:"size(64);null"`
	OpenId         string    `orm:"size(128);null"`
	OrderNo        string    `orm:"size(64);null"`
	SendStatus     string    `orm:"size(8);null"`
	CourierNo      string    `orm:"size(64);null"`  //快递单号
	ExpressCompany string    `orm:"size(128);null"` //快递公司
	Name           string    `orm:"size(128);null"`
	Phone          string    `orm:"size(64);null"`
	Province       string    `orm:"size(32);null"`
	City           string    `orm:"size(32);null"`
	Area           string    `orm:"size(32);null"`
	Address        string    `orm:"size(256);null"`
	Created        time.Time `orm:"auto_now_add;type(datetime);null"` //数据建立时间
	Updated        time.Time `orm:"auto_now;type(datetime);null"`     //数据最后一次修改时间
	ReceiveDate    string    `orm:"size(64);null"`
}

func (this *Order) Insert() error {
	if _, err := orm.NewOrm().Insert(this); err != nil {
		return err
	}
	return nil
}

func (this *Order) Update(fields ...string) error {
	if _, err := orm.NewOrm().Update(this, fields...); err != nil {
		return err
	}
	return nil
}

func (this *Order) Read(fields ...string) error {
	if err := orm.NewOrm().Read(this, fields...); err != nil {
		return err
	}
	return nil
}

func init() {
	orm.RegisterModel(new(Order))
}
